package com.foreknow.mapping;

import com.foreknow.db.DBManager;

import java.util.HashMap;
import java.util.Map;

public class MappingFactory {

    private static MappingFactory mappingFactory = null;
    private Map<String,EntityMapping> maps = new HashMap<>();
    public static final String ADMIN_MAPPING = "adminMapping";
    public static final String USER_MAPPING = "userMapping";
    public static final String GUESTBOOK_MAPPING = "guestbookMapping";

    private MappingFactory(){
    }

    public static MappingFactory getInstance() {
        if (mappingFactory == null) {
            mappingFactory = new MappingFactory();
            //向Map集合中保存xxxMapping对象
            mappingFactory.maps.put(ADMIN_MAPPING,new AdminMapping());
            mappingFactory.maps.put(USER_MAPPING,new UserMapping());
            mappingFactory.maps.put(GUESTBOOK_MAPPING,new GuestbookMapping());
        }
        return mappingFactory;
    }

    public EntityMapping getMapping(String key) {
        return maps.get(key);//AdminMapping()/UserMapping()
    }

}
